/** @jsxImportSource @emotion/react */
import * as React from "react";
import {RepLink, ReportViewProps,} from "../../common/base";
import {末尾链接, } from "../../common/rarelyVary";
import {
    CCell, Cell, RCell, Table, TableBody, TableRow, Text, useMMenuBarOcup, useTheme
} from "customize-easy-ui-component";
import {ReportFirstPageHeadCyMa} from "../../valve/rarelyVary";
import {config证书概况} from "./Regular.O-1";
import {TwoRaftDeviceInfo} from "../../contain/views";
import {Global} from "@emotion/react";
import {检验结论报告} from "./Conclusion";

//页面出现有滚动条和没有滚动条之间摇摆，从而使得页面晃悠 content-visibility; # height: touchScr? undefined : '100vh',
//内容恰好在一个屏幕高度的：台式机浏览器滚动条宽度出现与否导致内容高度更新矛盾，811px左右的屏幕：有可能导致的：#右边若有编辑器，也会有可能出现的毛病，不仅是独立显示正式报告时刻。
//【问题】在2半边编辑器形态下的没法完全避免此问题！！  Thframe 若用这个效果也不同！ 小范围先试看。
export const ReportView: React.FunctionComponent<ReportViewProps> = ({
    repId,   source: orc,  verId,rep,
}) => {
    const theme= useTheme();
    // const [rootMenu]=useRepMenuDirItems(VsProjects默认, orc.Projects, `/reportView/${rep?.modeltype}/ver/${verId}/${repId}`);
    //触摸屏 一般就没有滚动条的：        isWideSrc? "50%" : touchScr? "100%" : `calc(100% - ${theme.iconSizes.md} - 0.3rem)`,
    //菜单条的高度barHeight预留位置： paddingBottom 大屏幕48px, 其它的30px； 祸首菜单条;   const {touchScr,barHeight, } = useMMenuBarOcup(false);
    const {barHeight, } = useMMenuBarOcup(false);
  return (
    <React.Fragment>
        <Global
            styles={{
                html: {
                    "#root": {
                        contain: 'size',
                        containIntrinsicSize: `calc(100vh - ${barHeight})`,
                        overflowY: 'auto',
                        "@media print": {
                            contain: 'unset',
                            overflowY: 'unset',
                        },
                    },
                    "#root > .ViewReportMain": {
                        contentVisibility: 'auto',
                    }
                }
            }}
        />
        <div css={{"@media not print": {marginTop: '1rem', marginBottom: '1rem'}}}>
          {'符合'===orc?.检验结论  && <CertificatePage orc={orc} rep={rep}/>}

          {检验结论报告({theme, orc, rep})}
        </div>
        {末尾链接({template: rep?.modeltype, verId, repId: repId || ''})}
    </React.Fragment>
  );
}
//适合打印 A4纸张 竖版 一张纸的。
//content-visibility: auto 可能会与某些 CSS 属性（如 position: sticky）不兼容。
export const CertificatePage= ({ orc, rep, children} : { orc: any,rep: any,children?: React.ReactNode}
) => {
    const theme= useTheme();
    const callback = () => {
        return <div  css={{"@media print": {height:'100vh', overflowY: 'hidden',} }}>
            { ReportFirstPageHeadCyMa({theme,rep, mbbm:'FJB/DA-1041-2020',nMa:true}) }
            <div css={{
                "@media print": {
                    display: 'flex',
                    flexDirection: 'column',
                    justifyContent: 'space-around',
                    height: 'calc(100vh - 4rem)',     //剪掉上面头部的高度
                }
            }}>
                <Text variant="h3" css={{textAlign:'center', "@media print": {fontSize: theme.fontSizes[5],},}}>
                    特种设备制造监督检验证书
                </Text>
                <Text variant="h5" css={{textAlign:'center'}}>（压力管道元件制造）</Text>
                <div>
                    <div css={{display: 'flex',justifyContent: 'space-between',}}>
                        &nbsp;
                        <Text css={{display: 'flex',flexDirection: 'row-reverse',marginRight: '2rem'
                        }}>证书编号：{rep.isp?.no}</Text>
                    </div>
                    <Table fixed={ ["11%", "38%", "9%", "%"] }  css={ {borderCollapse: 'collapse',
                                                   "@media print": {height:'72vh',} } } tight  miniw={800}>
                        <TableBody>
                            <TwoRaftDeviceInfo orc={orc} rep={rep} config={config证书概况} tag='Conclusion'/>
                            <RepLink rep={rep} tag='Conclusion'>
                                <TableRow>
                                <CCell colSpan={4}>
                                        <Table  fixed={ ["24%", "39%", "6%", "%"] }
                                                css={ {borderCollapse: 'collapse', "@media print": {height:'fill-available'},} }  tight  miniw={800}>
                                            <TableBody>
                                                {orc?.检验结论==='符合' && <TableRow>
                                                        <Cell css={{border:'none',textIndent:'2rem',}} colSpan={4}>
                                                            <Text css={{minHeight:'9rem',display:'flex',lineHeight: 1.9,margin: '1rem'}}>
                                                                按照《中华人民共和国特种设备安全法》、《特种设备安全监察条例》的规定，该批产品经本机构实施监督检验，
                                                                安全性能 符合 &nbsp; { orc?.评定标准??'／' } &nbsp;的要求， 特发此证书。
                                                            </Text>
                                                        </Cell>
                                                    </TableRow>
                                                }
                                                <TableRow css={{"@media print": {height:'3rem'} }}>
                                                    <RCell css={{border:'none'}}>监督检验人员：</RCell>
                                                    <Cell css={{border:'none'}}>机erter</Cell>
                                                    <RCell css={{border:'none'}}>日期：</RCell>
                                                    <Cell css={{border:'none'}}></Cell>
                                                </TableRow>
                                                <TableRow css={{"@media print": {height:'3rem'} }}>
                                                    <RCell css={{border:'none'}}>审   核：</RCell>
                                                    <Cell css={{border:'none'}}></Cell>
                                                    <RCell css={{border:'none'}}>日期：</RCell>
                                                    <Cell css={{border:'none'}}>2024-04-10</Cell>
                                                </TableRow>
                                                <TableRow css={{"@media print": {height:'3rem'} }}>
                                                    <RCell css={{border:'none'}}>批   准：</RCell>
                                                    <Cell css={{border:'none'}}></Cell>
                                                    <RCell css={{border:'none'}}>日期：</RCell>
                                                    <Cell css={{border:'none'}}>2024-04-10</Cell>
                                                </TableRow>
                                                <TableRow>
                                                    <RCell css={{border:'none'}}>监检机构：</RCell>
                                                    <Cell colSpan={2} css={{border:'none'}}>{rep?.isp?.ispu?.name}</Cell>
                                                    <CCell css={{border:'none'}}>（监督检验机构检验专用章）</CCell>
                                                </TableRow>
                                                <TableRow css={{"@media print": {height:'fill-available'} }}>
                                                    <RCell  css={{border:'none'}}>监督检验机构核准证号：</RCell>
                                                    <Cell  colSpan={2} css={{border:'none'}}>{rep?.isp?.ispu?.agency?.apno}</Cell>
                                                    <CCell css={{border:'none'}}>2024-04-10</CCell>
                                                </TableRow>
                                            </TableBody>
                                        </Table>
                                    </CCell>
                                </TableRow>
                            </RepLink>
                        </TableBody>
                    </Table>
                </div>
                <Text css={{fontSize:'0.8rem'}}>注：本证书一式三份，一份监督检验机构存档，两份送制造单位，其中一份由制造单位随产品出厂资料交付。
                </Text>
            </div>
        </div>
    }
    return <>
        <div id="Certificate"/>
        {callback()}
    </>;
};
